package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.domain.clue.CluePoolDO;
import com.qk.dto.clue.*;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.common.Result;
import com.qk.vo.clue.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/clues")
@SuppressWarnings("all")
public class ClueController {

    @Autowired
    private ClueService clueService;


    @GetMapping("/pool")
    public Result getCluePool(CluePoolDTO dto){
        PageResult<CluePoolDO> pageResult = clueService.getCluePool(dto);
        return Result.success(pageResult);
    }



    @PutMapping("/false/{id}")
    public Result toFalseClue(@PathVariable Integer id, @RequestBody FalseClueDTO dto){

        clueService.toFalseClue(id,dto);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id){

        clueService.toBusiness(id);
        return Result.success();
    }




    @LogAnno
    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto){
        log.info("=========================Controller 中 方法updateClueInfoById 处理线程名称是：{}",Thread.currentThread().getName());
        clueService.updateClueInfoById(dto);
        return Result.success();
    }

    @LogAnno
    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id){
       ClueVO cluevo = clueService.getClueInfoById(id);
       return Result.success(cluevo);
    }



    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable Integer clueId, @PathVariable Integer userId){
        clueService.updateById(ClueDO.builder()
                .id(clueId)
                .userId(userId)
                .updateTime(LocalDateTime.now())
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build());
        return Result.success();
    }

    @LogAnno
    @GetMapping
    public Result list(ClueListDTO dto){
        PageResult<ClueDO> pageResult = clueService.clueList(dto);
        return Result.success(pageResult);
    }

    @LogAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDTO dto){
        clueService.addClue(dto);
        return Result.success();
    }


}